package s3;

import cn.hutool.core.img.Img;
import cn.hutool.core.io.FileUtil;
import com.amazonaws.services.s3.AmazonS3;
import net.coobird.thumbnailator.Thumbnails;

import java.awt.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @Author zhangtao
 * @create 2023/11/21 18:21
 */
public class S3Test {
    public static void main(String[] args) throws IOException {
        OssProperties properties = new OssProperties();
        properties.setEndpoint("http://10.218.221.239:8333");
        properties.setAccessKey("atm-user");
        properties.setSecretKey("password");
        OssTemplate ossTemplate = new OssTemplate(properties);
        ossTemplate.afterPropertiesSet();


        String srcPic = "D:\\个人资料\\智能货物\\SOC\\灵枢Sprint1123\\工具中心sonar.png";
        InputStream srcPicStream = Files.newInputStream(Paths.get(srcPic));
        //生成图片缩略图
        InputStream inputImageStream = ImageWUtil.imageConversion2ImgStream(srcPicStream, "image");
        Thumbnails.of(new File(srcPic))
                .forceSize(300, 300)
                .toFile("thumbnail-05-force-size.jpg");

        try (ByteArrayOutputStream img = new ByteArrayOutputStream()) {
            Thumbnails.of(new File(srcPic))
//                    .forceSize(300, 300)
                    .scale(0.2D)
                    .toOutputStream(img);
            inputImageStream = new ByteArrayInputStream(img.toByteArray());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        ossTemplate.putObject("aop","test/thumb-工具中心sonar.png", inputImageStream);
//        ossTemplate.putObject("aop","test/工具中心sonar.png", FileUtil.getInputStream("D:\\个人资料\\智能货物\\SOC\\灵枢Sprint1123\\工具中心sonar.png"));
        System.out.println(ossTemplate.generatePresignedUrl("aop", "test/thumb-工具中心sonar.png", 5));
    }
}
